package com.automannn.atm_back.modules.codeGenerator.controller;

import com.automannn.atm_back.common.api.vo.Result;
import com.automannn.atm_back.modules.codeGenerator.entity.GlobalConfigGroupEntity;
import com.automannn.atm_back.modules.codeGenerator.service.GlobalConfigGroupEntityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (GeneratorGlobalConfigGroup)表控制层
 *
 * @author chenkaihai
 * @since 2020-07-12 17:00:45
 */
@RestController
@RequestMapping("codeGenerator/generatorGlobalConfigGroup")
@Valid
public class GlobalConfigGroupEntityController {
    /**
     * 服务对象
     */
    @Resource
    private GlobalConfigGroupEntityService globalConfigGroupEntityService;


    /**
     * 分页查询所有数据
     */
    @GetMapping("list")
    public Result selectAll(Page<GlobalConfigGroupEntity> page, GlobalConfigGroupEntity globalConfigGroupEntity) {
        Result result = new Result();
        IPage<GlobalConfigGroupEntity> pageList = globalConfigGroupEntityService.queryAll(page, globalConfigGroupEntity);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable String id) {
        return Result.ok(globalConfigGroupEntityService.queryOne(id));
    }

    /**
     * 新增数据
     */
    @PostMapping("add")
    public Result insert(@RequestBody GlobalConfigGroupEntity globalConfigGroupEntity) {
        this.globalConfigGroupEntityService.insert(globalConfigGroupEntity);
        return Result.ok("新增成功!");
    }

    /**
     * 修改数据
     */
    @PutMapping("edit")
    public Result update(@RequestBody GlobalConfigGroupEntity globalConfigGroupEntity) {
        this.globalConfigGroupEntityService.update(globalConfigGroupEntity);
        return Result.ok("修改成功!");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result delete(String id) {
        return Result.ok(this.globalConfigGroupEntityService.deleteById(id));
    }

}
